package cn.edu.swu.ws.io;

import java.io.*;
import java.util.Calendar;

public class FileCopyer {

    public void copy(String sourceFilePath, String targetFilePath) {
        long start = Calendar.getInstance().getTimeInMillis();
        try (FileInputStream inputStream = new FileInputStream(sourceFilePath)) {
            File outFile = new File(targetFilePath);
            File dirs = outFile.getParentFile();
            dirs.mkdirs();

            try (FileOutputStream outputStream = new FileOutputStream(targetFilePath)) {
                int count;
                byte[] buffer = new byte[1024 * 4];
                while((count = inputStream.read(buffer)) != -1) {
                    outputStream.write(buffer, 0, count);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        long end = Calendar.getInstance().getTimeInMillis();
        System.out.println("time usage : " + (end - start) );
    }

}
